// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue';
import 'normalize.css';
import Router from 'vue-router';
import element from 'element-ui';
import App from './App';
import '../node_modules/element-ui/lib/theme-chalk/index.css';
import login from './components/login';
import reg from './components/reg';
import details from './components/details';
import aa from './components/aa';
import api from './http/api';

Vue.prototype.api = api;
const router = new Router({
  routes: [
        {
          path: '/login',
          name: 'login',
          component: login,
        },
        {
          path: '/reg',
          name: 'reg',
          component: reg,
        },
        {
          path: '/details',
          name: 'details',
          component: details,
          meta:{
            requireLogin: true,
          },
          children: [
            {
              path: 'details_a',
              name: 'details_a',
              component: aa,
            },
          ],
        },
  ],
});
const auth = true;
router.beforeEach((to, from, next) => {
  if (to.matched.some((value => value.meta.requireLogin))) {
    if (auth) {
      next();
    } else {
      next('/login');
    }
  }else {
      next();
    }
});
Vue.config.productionTip = false;
Vue.use(element);
Vue.use(Router);
/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
});
